package com.hopes.bizz.risk.transfer.mq;

import com.alibaba.fastjson.JSON;
import com.hopes.bizz.risk.transfer.dto.RiskTransferData;
import com.hopes.bizz.risk.transfer.service.RiskConsumerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author lyb
 * @version 1.0
 * @date 2024/2/19 10:33
 */
@Component
@Slf4j
public class RiskDataConsumer {
    @Resource
    private RiskConsumerService riskConsumerService;

    @JmsListener(destination = "MQ:RISK", containerFactory = "queueListener")
    public void consumer(String message) {
        try {
            log.info("收到风险数据，消息内容:{}", message);
            RiskTransferData riskTransferData = JSON.parseObject(message, RiskTransferData.class);
            riskConsumerService.handler(riskTransferData);
        } catch (Exception e) {
            log.error("消息消费失败,原因: {}", e.getMessage());
        }
    }


}